package com.cardbaobao.cardbabyclient.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;
import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.ui.activity.CreditCardRaidersActivity;
import com.cardbaobao.cardbabyclient.callback.RecycleItemClickedCallback;

/**
 * Created by Jiangzx on 10:46.
 */

public class RaidersFooterDelegateAdapter extends DelegateAdapter.Adapter<RecyclerView.ViewHolder> {
    public static final int POSITION_LOAD_MORE=-1;
    private RecycleItemClickedCallback clickedCallback;
    public void setRecycleItemClickedCallback(RecycleItemClickedCallback clickedCallback){
        this.clickedCallback=clickedCallback;
    }
    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(parent.getContext()).
                inflate(R.layout.item_raiders_footer,parent,false);
        return new RaidersFooterHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((RaidersFooterHolder)holder).tvMoreRaiders.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(clickedCallback!=null){
                    clickedCallback.onRecycleItemClicked(POSITION_LOAD_MORE);
                }
            }
        });
    }

    @Override
    public int getItemViewType(int position) {
        return CreditCardRaidersActivity.RAIDERS_FOOTER;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    private class RaidersFooterHolder extends RecyclerView.ViewHolder{
        private TextView tvMoreRaiders;
        private RaidersFooterHolder(View itemView){
            super(itemView);
            tvMoreRaiders= (TextView) itemView.findViewById(R.id.tv_raiders_more);
        }
    }
}
